package com.example.su_shi_tan_mine.child

import android.os.Bundle
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import com.alibaba.android.arouter.facade.annotation.Route
import com.example.su_shi_tan_bas_lib.base.BaseDataBindingFragment
import com.example.su_shi_tan_bas_lib.base.BaseFragmentEx
import com.example.su_shi_tan_core.arouter.MineARouter
import com.example.su_shi_tan_mine.R
import com.example.su_shi_tan_mine.databinding.SharePostFragmentBinding

@Route(path = MineARouter.SHARE)
class SharePostFragment:BaseDataBindingFragment<SharePostFragmentBinding>() {

    override fun layoutId()=R.layout.share_post_fragment

    private val page= arrayOf<BaseFragmentEx>(
        SharePostAdvertiseFragment.newInstance(),
        SharePostFansFragment.newInstance()
    )

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val mToolbar: Toolbar = view.findViewById(R.id.mToolbar)
        mToolbar.title = "分享推广"
        mToolbar.setNavigationOnClickListener { onBackPressedSupport() }

        viewBinder.mViewPager.adapter=object :
            FragmentPagerAdapter(childFragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT){
            override fun getCount(): Int {
                return page.size
            }

            override fun getItem(position: Int): Fragment {
                return page[position]
            }

            override fun getPageTitle(position: Int): CharSequence? {
                val shareLabel=getItem(position) as SharePostLabel
                return shareLabel.labelInfo()
            }
        }
        viewBinder?.mTabLayout?.setupWithViewPager(viewBinder.mViewPager)
    }


    override fun onBackPressedSupport(): Boolean {
        pop()
        return true
    }

}